package logic.baselogic;

/**
 * Created by IntelliJ IDEA.
 * User: grigory.rozhkov
 * Date: 12.09.12
 * Time: 0:47
 * To change this template use File | Settings | File Templates.
 */
public class Person {
    private String name;
    private String phone;
    public static final int NUMBER_OF_FEATURES = 2;

    public Person(String name, String phone) {
        this.name = name == null ? "" : name;
        this.phone = phone == null ? "" : phone;
    }

    public Person(String... fields) {
        switch (fields.length) {
            case 0: {
                name = "";
                phone = "";
                break;
            }
            case 1: {
                name = fields[0];
                phone = "";
                break;
            }
            case 2: {
                name = fields[0];
                phone = fields[1];
                break;
            }
        }
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? "" : name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone == null ? "" : phone;
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("\nNAME: ");
        stringBuilder.append(name);
        stringBuilder.append("\nPHONE: ");
        stringBuilder.append(phone);
        return stringBuilder.toString();
    }

    private void reset() {
        setName("");
        setPhone("");
    }

    public void updateFields (String ... fields){
        reset();
        if (fields.length > 0) {
            setName(fields[0]);
        }
        if (fields.length > 1) {
            setPhone(fields[1]);
        }
    }
}
